
package com.ami.kvm.jviewer.gui;

import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.kvm.jviewer.common.IAVIOutputStream;
import com.ami.kvm.jviewer.common.IAVIOutputStream.VideoFormat;
import com.ami.kvm.jviewer.videorecord.VideoRecordApp;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import javax.imageio.ImageIO;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

public class ImagesToVideo extends TimerTask {
	private IAVIOutputStream out = null;

	private String movFile;
	private String imagePath;
	private long numOfFrames;
	private long duration;
	private int i = 1;
	private long count;
	private double scalex;
	private double scaley;
	private File frameFile;
	private BufferedImage image;
	private boolean singleVideo;
	public Timer imagesToVideo;
	private int currentFile = -1;
	private int totalFiles = -1;

	public ImagesToVideo(String paramString1, String paramString2, long paramLong1, long paramLong2) {
		this.movFile = paramString1;
		this.imagePath = paramString2;
		this.numOfFrames = paramLong1;
		this.duration = paramLong2;
		this.singleVideo = JViewerApp.getInstance().getM_videorecord().singleVideo;

		if (JViewerApp.getInstance().getVideorecordapp() != null) {
			this.currentFile = JViewerApp.getInstance().getVideorecordapp().getFileIndex();
			this.totalFiles = JViewerApp.getInstance().getVideorecordapp().getVideotmpstorepath().length;
		}

		if ((paramLong1 > 0L) && (paramLong1 > JViewerApp.getInstance().getM_videorecord().getM_videorecord()
				.getNum_blank_frames())) {
			this.out = ((IAVIOutputStream) JViewerApp.getInstance()
					.createObject("com.ami.kvm.jviewer.avistream.AVIOutputStream"));
			this.out.initVideoFrames();
			this.out.setOutputFile(new File(paramString1));
			this.out.setVideoFormat(IAVIOutputStream.VideoFormat.JPG);
			this.out.setSingleVideo(this.singleVideo);

			this.out.setVideoCompressionQuality(0.75F);
			this.out.setTimeScale(paramLong2);
			this.out.setFrameRate(paramLong1);
		}

		this.image = new BufferedImage(1024, 768, 1);
		this.imagesToVideo = new Timer(true);
		this.imagesToVideo.schedule(this, 0L);
	}

	public void run()
   {
     try
     {
       if ((this.numOfFrames > 0L) && (this.numOfFrames > JViewerApp.getInstance().getM_videorecord().getM_videorecord().getNum_blank_frames())) {
         for (this.count = 0L; this.count < this.numOfFrames; this.count += 1L) {
           if ((!this.singleVideo) && (this.out.isStreamClosed()))
             multipleVideos();
           String localObject1 = "file" + this.count + ".jpeg";
           this.frameFile = new File(this.imagePath, (String)localObject1);
           this.image = ImageIO.read(this.frameFile);
           if ((this.singleVideo) && ((this.image.getWidth() != 1024) || (this.image.getHeight() != 768))) {
             this.image = singleVideo(this.image);
           }
           if (this.out.writeFrame(this.image))
             this.frameFile.delete();
         }
       }
       if (this.out != null) {
         this.out.close();
       }
       cancel();
       if (!JViewer.isdownloadapp()) {
         JViewerApp.getInstance().getM_wndFrame().getWindowMenu().setMessage("");
       }
       Object localObject1 = JViewerApp.getInstance().getMainWindow();
       VideoRecord.Record_Processing = false;
       if (JViewerApp.getInstance().getM_frame().videoStopError != null) {
         JViewerApp.getInstance().getM_frame().videoStopError.dispose();
       }
       else if (JViewer.isdownloadapp()) {
         JViewerApp.getInstance().getVideorecordapp().disposeInformationDialog();
         if (VideoRecord.file_creat_success == true) {
           JOptionPane.showMessageDialog((Component)localObject1, LocaleStrings.getString("L_1_ITOV") + LocaleStrings.getString("L_7_ITOV") + this.movFile + LocaleStrings.getString("L_2_ITOV"), LocaleStrings.getString("L_3_ITOV"), 1);
         }
         else {
           JOptionPane.showMessageDialog((Component)localObject1, LocaleStrings.getString("L_1_ITOV") + LocaleStrings.getString("L_8_ITOV") + LocaleStrings.getString("L_7_ITOV") + this.movFile + LocaleStrings.getString("L_2_ITOV"), LocaleStrings.getString("L_3_ITOV"), 1);
         }
         
 
         JViewerApp.getInstance().getVideorecordapp().setFileIndex(++this.currentFile);
         
         if (this.currentFile < this.totalFiles)
         {
           JViewerApp.getInstance().getVideorecordapp().availToConvert = true;
           synchronized (JViewerApp.getInstance().getVideorecordapp().convert) {
             JViewerApp.getInstance().getVideorecordapp().convert.notify();
           }
         } else {
           JViewerApp.getInstance().getM_frame().windowClosed();
         }
       }
       else {
         File tianlin = new File(JViewerApp.getInstance().getM_videorecord().Temp_store_Path);
         tianlin.delete();
         if ((this.numOfFrames <= 0L) || (this.numOfFrames <= JViewerApp.getInstance().getM_videorecord().getM_videorecord().getNum_blank_frames())) {
           InfoDialog.showDialog(JViewer.getMainFrame(), LocaleStrings.getString("L_9_ITOV"), LocaleStrings.getString("L_3_ITOV"), 1);
         }
         else if (VideoRecord.file_creat_success == true) {
           InfoDialog.showDialog(JViewer.getMainFrame(), LocaleStrings.getString("L_7_ITOV") + this.movFile + "\n" + LocaleStrings.getString("L_4_ITOV") + (int)VideoRecord.Avg_fps + LocaleStrings.getString("L_5_ITOV"), LocaleStrings.getString("L_3_ITOV"), 1);
 
         }
         else
         {
           InfoDialog.showDialog(JViewer.getMainFrame(), LocaleStrings.getString("L_8_ITOV") + LocaleStrings.getString("L_7_ITOV") + this.movFile + "\n" + LocaleStrings.getString("L_4_ITOV") + (int)VideoRecord.Avg_fps + LocaleStrings.getString("L_5_ITOV"), LocaleStrings.getString("L_3_ITOV"), 1);
         }
       }
       
 
 
 
 
 
 
       if ((!JViewer.isdownloadapp()) && (
         (JViewerApp.getInstance().GetRedirectionState() == JViewerApp.REDIR_STARTED) || (JViewerApp.getInstance().GetRedirectionState() == JViewerApp.REDIR_STARTING)))
       {
         JViewerApp.getInstance().getJVMenu().notifyMenuStateEnable("VideoRecordStart", true);
         JViewerApp.getInstance().getJVMenu().notifyMenuStateEnable("VideoRecordSettings", true);
       }
       String str;
       return;
     } catch (IOException localIOException2) {
       try {
         if (this.out != null)
           this.out.close();
       } catch (IOException localIOException4) {
         Debug.out.println(localIOException4);
       }
       cancel();
       String str = LocaleStrings.getString("L_6_ITOV");
       JViewerApp.getInstance().getM_videorecord().OnLowDiskSpace(this.frameFile, str);
     } finally {
       try {
         if (this.out != null)
           this.out.close();
       } catch (IOException localIOException5) {
         Debug.out.println(localIOException5);
       }
     }
   }

	private BufferedImage singleVideo(BufferedImage paramBufferedImage) {
		BufferedImage localBufferedImage = new BufferedImage(1024, 768, 1);
		this.scalex = (1024.0D / paramBufferedImage.getWidth());
		this.scaley = (768.0D / paramBufferedImage.getHeight());
		AffineTransform localAffineTransform = AffineTransform.getScaleInstance(this.scalex, this.scaley);
		Graphics2D localGraphics2D = localBufferedImage.createGraphics();
		localGraphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
		localGraphics2D.drawRenderedImage(paramBufferedImage, localAffineTransform);
		return localBufferedImage;
	}

	private void multipleVideos() {
		this.count -= 1L;
		this.out.setStreamClosed(false);
		this.out = ((IAVIOutputStream) JViewerApp.getInstance()
				.createObject("com.ami.kvm.jviewer.avistream.AVIOutputStream"));
		this.out.initVideoFrames();
		this.out.setOutputFile(new File(this.movFile + "_" + this.i + ".avi"));
		this.out.setVideoFormat(IAVIOutputStream.VideoFormat.JPG);
		this.out.setSingleVideo(this.singleVideo);
		this.out.setFrameRate(this.numOfFrames);
		this.out.setTimeScale(this.duration);
		this.out.setVideoCompressionQuality(1.0F);
		this.i += 1;
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\jviewer\gui\ImagesToVideo
 * .class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */